var express=require('express');
var router=express.Router();
var axios = require('axios');

router.get('/',function(req,res,next){
    // res.send("后台主页页面");
    var userId = req.query
    // console.log(userId)
    var config = {
          method: 'post',
        baseURL: 'http://localhost:9022',
        url: '/tb-user/getAllUsersByStatus',
        params: {
            Status:0
        },
    }
    axios(config)
        .then(function (response) {
            console.log(response.data);
            if (response.data.code == 'success') {
                console.log("获取普通用户信息成功");
                var data = response.data.data
                res.render('backstage/backIndex', {
                    list: data
                });
            } else {
                // console.log(response);
                res.send({ err: -1, msg: "获取普通用户信息失败" })
                console.log("获取普通用户信息失败")
                console.log(testNumber)
            }
        })
        .catch(function (error) {
            // console.log(error);
            res.send({ err: -1, msg: "服务器错误，请刷新页面" })
            console.log("服务器错误")
        });
})

router.post('/delete', (req, res) => {
    let { userId } = req.query
    console.log(userId)
    var config = {
        method: 'post',
        baseURL: 'http://localhost:9022',
        url: '/tb-user/deleteUserById',
        params: {
            userId:7
        },
        headers: {//指定响应头
            "Content-Type": "application/json;charset=utf-8",
            "Accept": "application/json"
        }
    }
    axios(config)
        .then(function (response) {
            if (response.data.code=='success'){
                console.log("-----------------------------")
                // res.redirect('/backstage/backIndex');//成功后回到个人中心页面
            }else{
                console.log("-+++++++++++++++++++++++++++++++++++")
                // res.redirect('/backstage/backIndex');//成功后回到zhu页面
            }
        })
        .catch(function (error) {
            console.log("******************************************");
            console.log(error);
            console.log("失败")
        });

})

module.exports=router;
